Add warning when registering struct functions as workflows#1996
Add warning when registering struct functions as workflows#1996yuandrew wants to merge 4 commits intotemporalio:masterfrom
Conversation
| aw.executionParams.DefaultVersioningBehavior == VersioningBehaviorUnspecified { | ||
| panic("workflow type does not have a versioning behavior") | ||
| } | ||
| _, ok := w.(WorkflowDefinitionFactory) |
There was a problem hiding this comment.
Will this effect the PHP SDK? I think this functionality is used by them
There was a problem hiding this comment.
I misunderstood how the user was registering struct methods, the new commit should be correct, manually repro'd the issue.
Is PHP SDK built on top of Go?
There was a problem hiding this comment.
Is PHP SDK built on top of Go?
Yep
|
I am not sure we should be warning here, there is nothing inherently non deterministic in using a It would only be non deterministic if a user didn't respect the contract to return a new instance with each call. |
| } | ||
| fnName := runtime.FuncForPC(reflect.ValueOf(w).Pointer()).Name() | ||
| if strings.HasSuffix(fnName, "-fm") { | ||
| aw.logger.Warn("It is recommended to only use struct methods to define activity functions. In some cases, struct methods as workflows may cause NDE errors.") |
There was a problem hiding this comment.
nit could we log the function they tried to register here too?
| } | ||
| fnName := runtime.FuncForPC(reflect.ValueOf(w).Pointer()).Name() | ||
| if strings.HasSuffix(fnName, "-fm") { | ||
| aw.logger.Warn("Registering workflow" + fnName + ". It is recommended to only use struct methods to define activity functions. In some cases, struct methods as workflows may cause NDE errors.") |
There was a problem hiding this comment.
Pedantic, but would avoid the acronym NDE in user-facing contexts
There was a problem hiding this comment.
thanks for the suggestion :)
cretz
left a comment
There was a problem hiding this comment.
(approving because I technically left a comment here, but my approval on Go issues these days can be ignored heh)
|
Decided internally that since this spams our test logs (our test workflows are all methods under the same struct), for now we'll add something in the documentation warning against this. Our tests can be changed to not share the same struct, but that's a rather large refactor. |
What was changed
Added a warning log saying we suggest only using structs for activity registration
Why?
Help prevent users from hitting potential NDEs
Checklist
Closes SDK should warn when using structures to define a workflow #1986
How was this tested:
N/A, only added a log statement